/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package net.wofly.sale.order.repository;

import net.wofly.sale.order.domain.ReturnSales;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ReturnSalesRepository
        extends PagingAndSortingRepository<ReturnSales, String>, JpaSpecificationExecutor<ReturnSales> {
    
    Integer countByOrderIDAndStatusNotIn(String orderID, List<Integer> statusList);
    
    ReturnSales findByProcessInsID(String processInsID);
    
    List<ReturnSales> findByProcessInsIDIn(List<String> processInsIDs);
    
    @Query(value = "select SUBSTR(max(returnsalesno) ,9,12 ) as returnSalesNO from sale_order_returnsales where " +
            "returnsalesno like :dateStr% ", nativeQuery = true)
    Object findMaxReturnSalesNONoByDate(@Param(value = "dateStr") String dateStr);
    
}